<?php
/**
 * 网站设置
 *
 * @author Alen
 * @since 1.0.0 2013-10-5 sutroon
 */
class Site_SettingAction extends AdmincpAction {
    
    //put your code here
    public function index(){
        
        // 设置页面导航
        $this->set_breadcrumb(array('网站管理'=>'?m=Site_Setting','网站设置'=>'###'));
        
        // 设置页面标题
        $this->set_h1('');
        
        // 设置页面信息,如页面标题,meta信息等
        $this->set_page_info('网站管理');
        
        // 读取数据
        if(!$this->dm) $this->dm=new SoDataModule();
        $this->dm->tablename='tgeneraldata';
        $dataset=$this->dm->select_arrayset('', 'ExTags=\'SITE_INFO\'','Name, Value');
        $data=array();
        if($dataset){
            foreach($dataset as $row){
                $data[$row['Name']]=$row['Value'];
            }     
        }
        // 构建表单内容
        $this->uig->begin_form(true);
        $this->uig->add_textfield('网站名称','title',get_array_value($data, 'SITE_TITLE'),'标题长度不超过30个字符');
        $this->uig->add_textfield('页面标题后缀','titlesuffix',get_array_value($data, 'SITE_TITLE_SUFFIX'));
        $this->uig->add_textfield('页面关键词','keywords',get_array_value($data, 'SITE_KEYWORDS'));
        $this->uig->add_textfield('页面描述','description',get_array_value($data, 'SITE_DESCRIPTION'));
        $this->uig->add_filefield('Logo图片','logo',get_array_value($data, 'SITE_LOGO'));
        $this->uig->add_textfield('备案号码','miicode',get_array_value($data, 'SITE_MIICODE'));
        $this->uig->add_radiofield('网站状态','state',array('正常'=>1,'关闭'=>0),  get_array_value($data, 'SITE_STATE',1));
        $this->uig->add_editorfield('网站关闭消息','closemessage',get_array_value($data, 'SITE_CLOSE_MESSAGE'),6);
        $this->uig->add_controlfield();
        $this->uig->add_hiddenfield(array('action'=>'save'));
        $this->uig->end_form();
        $this->assign('form', $this->uig->get_text());    
        // 显示模板
        $this->display();
    }
    public function save(){
        
        $this->dm->tablename='tgeneraldata';
        $this->dm->add_param('SITE_TITLE',request_string('title'),'名称不能为空');
        if($this->dm->has_error())redirect($this->dm->get_error());
        $this->dm->add_param('SITE_TITLE_SUFFIX',request_string('titlesuffix'));
        $this->dm->add_param('SITE_KEYWORDS',request_string('keywords'));
        $this->dm->add_param('SITE_DESCRIPTION',request_string('description'));
        $this->dm->add_param('SITE_STATE',request_string('state'));
        $this->dm->add_param('SITE_CLOSE_MESSAGE',request_string('closemessage'));
        $logo=$this->upload_file('logo');
        if($logo) $this->dm->add_param('SITE_LOGO',$logo);
        foreach($this->dm->params as $n=>$v){
            if($this->dm->exists('ExTags=\'SITE_INFO\' and Name=\''.$n.'\'')){
                $this->dm->update_records('', 'Value='.$v.'', 'ExTags=\'SITE_INFO\' and Name=\''.$n.'\'');
            }else{
                $this->dm->insert_record('', 'Name, Value, ExTags', sprintf("'%s',%s,'SITE_INFO'",$n,$v));
            }
        }
        if($this->dm->has_error()){
            redirect($this->dm->get_error());
        }
        redirect('保存成功','?m=Site_Setting');
    }
}

?>
